/**
 * Created by Administrator on 2016/8/1.
 */
$(document).ready(function(){
    var $width = $(window).width();
    var $height = $(window).height();
    $(".mask").css({'height':$height+200,'width':$width});
    $(".go_or_not2 ").css("top","700px");
    $(".mainPart1 textarea").val(sessionStorage.description);
    if(sessionStorage.imgNum != 0&&sessionStorage.imgNum !== undefined){
        $(".information").css("display","none");
        var img =sessionStorage.img;
        var imgArray = img.split(";");
        console.log(imgArray);
        for(var i=0;i<imgArray.length;i++){
            var src= imgArray[i];
            var imgDiv= $("<section><img class=\"userImg\"><img src=\"../images/delete.png\" class=\"delete\" style=\"display: block;\"></section>");
            imgDiv.children("img:first-child").attr("src",src);
            imgDiv.insertBefore($("#defaultImg").parent());
        }
        $(".mainPart2 .imgGroup section .delete").click(function(){
            $(this).parent().remove();
            var length = $(".imgGroup .defaultImg").length;
            if(length>4){
                $("#defaultImg").css("display","none");
            }else{
                $("#defaultImg").css("display","block");
            }
        })
    }
    $("header img:first-child").click(function(){
        $(".go_or_not2 ").css("display","block");
        $(".mask").css("display","block");
        $(".go_or_not2 p:nth-child(2)").click(function(){
            history.go(-1);
        })
        $(".go_or_not2 p:nth-child(3)").click(function(){
            $(".go_or_not2 ").css("display","none");
            $(".mask").css("display","none");
        })
    })
    $("header p:nth-child(3)").click(function(){
        var description = $(".mainPart1 textarea").val();

        if(description.length>400){
            createWindow("文字输入在0-400字之间");
        }else{
            var image_num = $(".imgGroup section").length-1;
            var note_image =$(".imgGroup section").eq(0).children(".userImg").attr("src");
            if(note_image!=undefined){
                var describe_img = note_image;
            }
            for(var i=1;i<image_num-1;i++){
                var src = $(".imgGroup section").eq(i).children(".userImg").attr("src");
                describe_img = describe_img+";"+src;
            }
            sessionStorage.description =description;
            if(describe_img ==undefined){
                sessionStorage.img = '';
            }else{
                sessionStorage.img = describe_img;
            }
            sessionStorage.imgNum =image_num-1;
            history.go(-1);
        }
    })
});



//点击图片调用uploadfive
$(document).ready(function(){
    $(".imgGroup .defaultImg").click(function(){
        $("#uploadifive-file_upload input:last-child").click();
    })
});
var user_token =  sessionStorage.user_token;
var u_id = sessionStorage.u_id;
//uploadfive参数传递回调
$(function() {
    var splik;
    $('#file_upload').uploadifive({
        'fileObjName': 'upload',
        'auto'             : true,
        'formData'         : {
            user_token:user_token,
            device:"wap",
            'category':"describe_imgs",
            'u_id':u_id
        },
        'removeCompleted' : true,
        'multi' : true,
        //'uploadLimit' : 4,
        'simUploadLimit':10,
        'sizeLimit': 5120000,
        'fileType' : 'image/*',
        //'fileSizeLimit'   : 5242880,
        'queueID'          : 'queue',
        'uploadScript'     : commonval+'/uploadLiveImage',
        'onUploadComplete' : function(file, data) {
            $(".information").css("display","none");
            splik = JSON.parse(data);
            //图片回调展示
            $(".upLoad img").attr("src",commonval+splik.data);
            var img = $("<section><img class=\"userImg\"><img src=\"../images/delete.png\" class=\"delete\" style=\"display: block;\"></section>");
            var src = commonval+splik.data;
            img.children("img:first-child").attr("src",src);
            img.insertBefore($("#defaultImg").parent());
            //imgGroup展示区域
            var length = $(".imgGroup .defaultImg").length;
            if(length>4){
                $("#defaultImg").css("display","none");
            }
            $(".mainPart2 .imgGroup section .delete").click(function(){
                $(this).parent().remove();
                var length = $(".imgGroup .defaultImg").length;
                if(length>4){
                    $("#defaultImg").css("display","none");
                }else{
                    $("#defaultImg").css("display","block");
                }
            })
        }
    });
});